library(readr)
file=read_delim("/mnt/md1200/6/zhaocunyou/Genome_analysis_by_wzj/All_sample_merged.HC.VQSR.genotype.heter.txt",col_names=T,delim="\t")
group1=c("X2B_X1T","M8_M7","M6_M5","M2_M1","M48_M47","M50_M49","M28_M27","M30_M29","M26_M25","M35_M36","M18_M17","M20_M19","M22_M21","M40_M39")

ID1=c("X1T","X2B","SD1","SD1T","F15","F15T2","FC1","FC1T","FC6","FC6T","ZS6","ZS6T","JYS2","JYS2T","JYS1","JYS1T","FC2","FC2T","F14","F14T","FC3","FC3T","F10","F10T","F16","F16T","FC4","FC4T","CT1A","CT1B","CT2A","CT2B","CT3A","CT3B","CT5A","CT5B","JYS3","JYS3T","JYS4","JYS4T")
ID2=c("X1T","X2B","M7","M8","M5","M6","M1","M2","M41","M42","M43","M44","M47","M48","M3","M4","M11","M12","M27","M28","M29","M30","M25","M26","M36","M35","M32","M31","M17","M18","M19","M20","M21","M22","M39","M40","M49","M50","M51","M52")

disease=c(rep("SZ",4),rep("BD",10),"AD","AD","MDD","MDD","SZ","SZ",rep("BD",6),"AD","AD",rep("NC",8),rep("SZ",4))
status=c(rep(c("DCD","DCC"),9),rep("CC",10),rep("NC",8),rep(c("DCD","DCC"),2))

sample_info=data.frame(ID1,ID2,disease,status)

group1=unlist(strsplit(group1,"_"))
sample.info=sample_info[sample_info$ID2 %in% group1,]
sample.id=as.character(sample.info$ID1)
file1=file[,c("ID",names(file)[names(file) %in% sample.id])]

check=function(x){
str1=unlist(strsplit(as.character(x[2])," "))
if(str1[1]==str1[2]){ 
    return ("FALSE")
    }else{return ("TRUE")}
}
unitID=c()

col_names=c("FileName","heter.num")
result=data.frame(matrix(NA,1,ncol = 2))
names(result)=col_names
result=result[-1,]

for(j in 2:15){
result_tmp=data.frame(matrix(NA,1,ncol = 2))
names(result_tmp)=col_names
test=data.frame(ID=file1$ID,file1[,j])
test$group.heter=apply(test,1,check)
tmp_id=as.character(test[test$group.heter=="TRUE",]$ID)
result_tmp[,1]=names(test)[2]
result_tmp[,2]=length(tmp_id)
unitID=unique(c(unitID,tmp_id))
result=rbind(result,result_tmp)
}

length(unitID)
[1] 9045277

###DC
group1=c("X2B_X1T","M8_M7","M6_M5","M2_M1","M48_M47","M50_M49")

###CC
group1=c("M28_M27","M30_M29","M26_M25","M35_M36")

###HC
group1=c("M18_M17","M20_M19","M22_M21","M40_M39")



